<?php
/**
 * File: ConfirmPoints.php
 * Author: camy <375766145@qq.com>
 * Time: 2018/3/23 09:27
 */

namespace Common\Extend\DingTalk\Message\Project;

use Common\Extend\DingTalk\Message\BaseMessage;

class ConfirmPoints extends BaseMessage
{
    public function send($param)
    {
        //标题
        $this->title = '积分提醒';
        $allocateRecord = M('projectPointsAllocateRecord')->find($param['id']);
        //跳转地址
        $this->setUrl('project/points', ['project_id' => $allocateRecord['project_id'], 'type' => $allocateRecord['points_type']]);
        //发送人
        $userId = $allocateRecord['allocate_user_id'];
        $people = $this->getUserId($userId);
        //发送内容
        $memberName = M('user')->where(['id' => $allocateRecord['user_id']])->getField('name');
        $projectName = M('project')
            ->where(['id' => intval($allocateRecord['project_id'])])
            ->getField('name');
        if ($param['type'] == 1) {
            $operateType = '确认';
        } else {
            $operateType = '申述';
        }

        $text = "{$memberName}对【{$projectName}】项目积分进行了{$operateType}";
        $message = $this->getMessage($text);
        //发送消息
        dingtalk()->sendMessage($people, $message);

    }
}